package com.zhanggm.student.controller;


import com.zhanggm.springboot.starter.upload.service.FileService;
import com.zhanggm.springboot.starter.upload.util.FileResult;
import com.zhanggm.student.config.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@RestController
@RequestMapping("/file/")
public class UploadController {

    @Autowired
    private FileService fileService;

    @RequestMapping("upload")
    public ResponseResult upload(MultipartFile file){
        FileResult upload = null;
        try {
            upload = fileService.upload(file);
        } catch (IOException e) {
            e.printStackTrace();
            return ResponseResult.fail(10000,"文件上传失败");
        }
        return ResponseResult.success(upload);
    }
}
